function login() {
	// console.info("点击了登录");
	var email = $("#email").val();
	// console.info(userName)
	var Password = $("#Password").val();
	// console.info(userPass);
	var codelg = $("#codelg").val;
	var ets = document.getElementById("emailts");
	var pts = document.getElementById("passts");
	var cts = document.getElementById("codets");

	if (email == "" || email == null) {
		ets.innerHTML = "邮箱不能为空!";
		ets.style.color = "red";
		return false;
	}
	if (!isEmail(email)) {
		ets.innerHTML = "邮箱格式不正确!";
		ets.style.color = "red";
		return false;
	}
	if (Password == "" || Password == null) {
		pts.innerHTML = "密码不能为空";
		pts.style.color = "red";
		return false;
	}
/*	alert(codelg);
	if (codelg == "" || codelg == null) {
		alert(codelg);
		cts.innerHTML = "密码不能为空";
		cts.style.color = "red";
		return false;
	}*/
	
	$.ajax({
		type : "POST",
		url : "http://localhost:8080/Announcement/user/vertifyEmail",
		data : {
			'email' : email
		},
		dataType : "json",
		success : function(data) {
			if (!data.success) {
				alert("邮箱未注册!");
			}
		},
		error : function() {
			alert("邮箱错误!");
		}
	});
	return true;
}

function registerUser() {
	// alert("register"); // /////
	if (!checkemail()) {
		// alert("sss")
		return false;
	}
	if (!checkname()) {
		return false;
	}
	// /alert("register"); // /////
	if (!checkpass()) {
		return false;
	}
	if (!checkrpass()) {
		return false;
	}

	return true;
}
function checkemail() {
	var email = $("#email").val();
	var ets = document.getElementById("emailts");
	// alert(ets + "aaa"); // /////
	if (!isEmail(email)) {
		ets.innerHTML = "邮箱格式不正确!";
		ets.style.color = "red";
		return false;
	}
	$.ajax({
		type : "POST",
		url : "http://localhost:8080/Announcement/user/vertifyEmail",
		data : {
			'email' : email
		},
		dataType : "json",
		success : function(data) {
			if (data.success) {
				alert("邮箱已经被注册！");
				return false;
			}
		},
		error : function() {
			alert("网络连接出错！");
			return false;
		}
	});
	ets.innerHTML = "邮箱可以使用!";
	ets.style.color = "green";
	return true;
}

function isEmail(str) {
	// alert("ss");
	var reg = /[a-z0-9-]{1,30}@[a-z0-9-]{1,65}.[a-z]{3}/;
	return reg.test(str);
}

function checkname() {
	var name = $("#username").val();
	var ts = document.getElementById("namets");
	// alert(name); // /////
	if (name.length < 3 || name.length > 15) {
		ts.innerHTML = "用户名长度须在3-15之间!";
		ts.style.color = "red";
		return false;
	}
	$.post("checkUserName.action", {
		" userName" : name
	}, function(data) {
		var d = $.parseJSON(data);
		// console.log(d.success);
		if (d.success != true) {
			ts.innerHTML = '用户名已存在!';
			ts.style.color = 'red';
			return true;
		}
	});
	ts.innerHTML = '用户名可以使用！';
	ts.style.color = 'green';
	return true;
}
function checkpass() {
	var userPass = $("#password").val();
	var pts = document.getElementById("passts");
	// alert(userPass); // /////
	if (userPass.length < 6 || userPass.length > 15) {
		pts.innerHTML = "密码长度须在6-15之间!";
		pts.style.color = "red";
		return false;
	}
	pts.innerHTML = "密码可以使用!";
	pts.style.color = "green";
	return true;
}
function checkrpass() {
	var userPass = $("#repwd").val();
	var userRPass = $("#password").val();
	var prts = document.getElementById("passrts");
	// alert(userPass); // /////
	if (userPass != userRPass) {
		prts.innerHTML = "两次密码输入不一致!";
		prts.style.color = "red";
		return false;
	}
	prts.innerHTML = "输入一致!";
	prts.style.color = "green";
	return true;
}

$("input").focus(function(){
	  $(this).next().html("");
});


$(function() {

	

})
